package bots.lookahead;

import model.Field;
import model.Figure;
import model.GameType;
import model.MoveChooser;

import java.util.concurrent.ForkJoinPool;

/**
 * @author Alex Vikharev vikharev@yandex-team.ru
 *         created 27.02.12
 */
public class SuperLookAheadBot extends AbstractLookAheadBot {
    public SuperLookAheadBot(final String name, final GameType gameType, ForkJoinPool pool, MoveChooser chooser) {
        super(name, gameType, pool, chooser);
    }

    public SuperLookAheadBot(final String name, final GameType gameType, ForkJoinPool pool) {
        super(name, gameType, pool);
    }

    @Override
    public model.Position setFigure(final Field field, final Figure figure) {
        final int usedFigures = field.getUsedFigures().size();
        if (usedFigures < 2) {
            return setRandomFigure(field, figure);
        } else {
            int movesToLook;
            if (usedFigures < 3) {
                movesToLook = 1;
            } else if (usedFigures < 5) {
                movesToLook = 2;
            } else if (usedFigures < 8) {
                movesToLook = 3;
            } else if (usedFigures < 9) {
                movesToLook = 4;
            } else {
                movesToLook = 6;
            }

            Task task = new Task(field, figure, movesToLook);
            Result result = pool.invoke(task);
            return result.move;
        }
    }
}
